package com.lagou.homework.udf;

import org.apache.hadoop.hive.ql.exec.UDF;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;

public class WeekOfYear extends UDF {

    public int evaluate(String date){

        Calendar cal = Calendar.getInstance();
        SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");

        try {
            cal.setTime(format.parse(date));
        } catch (ParseException e) {
            e.printStackTrace();
        }

        int week = cal.get(Calendar.WEEK_OF_YEAR);
        return week;

    }
}
